<?php

namespace Action\Flow\GenericFlow\Item;

class Comments extends \Library\Action\UserAction
	implements \Library\Action\AjaxAction {

	private $_post;
	private $_comments;

	public function execute() {
		parent::execute();
		
		$post_id = (int) $this->getParam( 'id' );
		$this->_post = \Bean\Post::get( $post_id );
		
		_a( $this->_post->isViewable(), 'You can\'t see this post' );
	}

	public function getPost() {
		return $this->_post;
	}
	
	public function getComments() {
		if( $this->_comments === null ) {
			$comments = array();
			foreach( $this->_post->getComments() as $comment ) {
				$comments[] = new \Library\Widget\Comment( $comment );
			}
			$this->_comments = $comments;
		}
		return $this->_comments;
	}

}
